﻿using System;
using System.Windows.Data;
using System.Globalization;

namespace Silverlight.ControlToolkit.Converters
{
    public class CurrencyConverter : IValueConverter
    {

        public object Convert(object value,
                             Type targetType,
                             object parameter,
                             CultureInfo culture)
        {
            if (value != null)
                return string.Format("{0:c2}", value);
            else
                return "";
        }

        public object ConvertBack(object value,
                                  Type targetType,
                                  object parameter,
                                  CultureInfo culture)
        {

            if (value != null)
            {
                return System.Convert.ToDecimal(value);
            }
            else
                return value;
        }

    }
}
